<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <link href="/static/devtools30/layui/css/layui.css" rel="stylesheet" />
    <link href="/static/devtools30/css/devindexbase.css" rel="stylesheet" />
    <script src="/static/devtools30/js/jquery-1.11.2.min.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui/layui.all.js" type="text/javascript"></script>
    <script src="/static/devtools30/js/devtoolCommon.js" type="text/javascript"></script>
    <script src="/static/devtools30/layui-v2.5.6/dlcommon.js" type="text/javascript"></script>

</head>
<style>
    .soul-bottom-contion {
        height: 31px;
        /*line-height: 29px;*/
        border-top: solid 1px #e6e6e6;
        display:none;
    }
    .soul-bottom-contion .condition-items {
        display: inline-block;
        width: calc(100vw - 100px);
        height: 30px;
        float: left;
        overflow: hidden;
        white-space: nowrap;
        display:none;
    }
    .buttonclass{
        width:68px;height:24px;background:rgba(64,190,191,1);border-radius:2px;line-height: 24px;
    }
    .layui-inline{
        width: 120px;
    }

    .layui-btn-primary1 {
        border: 0px solid #C9C9C9;
        color: #0066CC;
        background-color: transparent;
        /*background: #ffffff;*/
    }
    .layui-btn:hover {
        color: black;
    }
    .layui-select{
        height: 24px;
        width: 120px;
    }
    .layui-btn, .layui-input, .layui-select, .layui-textarea, .layui-upload-button {
        -webkit-appearance: button
    }
    .layui-table, .layui-table-view {
        margin: 10px 0 0 0;
    }
    .layui-inline {
        width: 1px;
    }
    .fp-table{
        float: left;
        width:33%;
        height: 100%;
        padding-top: 10px;
        /*box-sizing: border-box;*/
        /*border: 1px solid #ddd;*/
    }
</style>
<body>
<div class="fapz-content">
    <div class="navheader form-inline" style="height:26px;margin-bottom: 0px;width: 100%;" id="div_navheader">
        <div class="flex flex-align-center flex-jusity-betreen tophead backgroundf">
            <div class="flex flex-align-center">
                <div class="layui-form flex flex-align-center" lay-filter="formTest">
                    <div class="layui-form-item" style="    margin-top: 10px;">
                        <label style="padding:0px 10px 0px 5px;">年份</label>
                        <div class="layui-inline" style="width: 80px">
                            <input type="text" class="layui-input" style="height: 24px;width: 80px" id="hsdate" name="hsdate" autocomplete="off" aria-autocomplete="off" placeholder="yyyy">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-btn-group btns tab1">
                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="imortExcel()">Excel导入</button>
                <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" onclick="downModel()">模板下载</button>
            </div>
        </div>



    </div>
    <div>
    <div class="fp-table" style="width: 13.5%">
        <table id="nytable" lay-filter="nytool"></table>
    </div>

    <div class="fp-table" style="margin-left:0.5%;width: 86%">
        <table id="fapztable" lay-filter="faptool" style="margin-bottom: 0px;"></table>
        <div id="pageid"  style="text-align: left;border:1px solid rgba(229, 229, 229, 1);border-top: none ;height: 41px"></div>
    </div>
    </div>
</div>

<script type="text/javascript" th:inline="javascript">

    var h = document.body.clientHeight; //弹窗的高度
    var w = document.body.clientWidth;//弹窗的宽度
        var selMonth='';
    var excelId=[[${excelId}]];

    layui.config({
        base: '/static/layui-v2.5.6/ext/',// 第三方模块所在目录
        version: 'v1.5.10' // 插件版本号
    });

    layui.use(["form","table",'laypage','layer'],function(){
        $=layui.jquery
        form=layui.form;
        layui.laydate.render({
            elem: '#hsdate'
            ,type: 'year'
        });
        if($("#hsdate").val()==''){
            $("#hsdate").val(new Date().getFullYear());
        }

        getMonth();
        fpgrid();

    })



    function searchBtn() {
        if(!$('#hsdate').val()){
            dLong.layerSuccess("请选择数据年份！");
            return
        }
        if(!selMonth){
            dLong.layerSuccess("请选择数据月份！");
            return
        }
        var postdata={
            year:$('#hsdate').val(),
            month:selMonth,
            excelId:excelId
        }
        dLong.post("/DevtExcelImportController/getExcelLogList",postdata,function(data){
            if (data.success) {
                fpgrid(data.data)
            }else {
                dLong.layerError(data.msg)
            }
        },true);
    }



    function getMonth() {
        var postdata={
        }
        dLong.getJSON("/DevtExcelImportController/getmonthlist",postdata,function(res){
            if (res.success) {
                nygrid(res.data)
            }
        },true);
    }


    function nygrid(data) {
        var table = layui.table;
        //第2个实例
        table.render({
            elem: '#nytable',
            height: "full-60",
            // width: 7* CLIENTWIDTH / 10,
            size: 'sm',
            page: false,
            limit:120000,
            cols: [
                [ //表头
                    {field: 'id',title: 'id',width: 300,sort: true,align: 'left',halign: 'center',hide:true},
                    {field: 'month',title: '数据月份',width: 200,sort: false,align: 'center',halign: 'center'},
                    {field: 'code',title: '数据月份',width: 300,sort: true,align: 'left',halign: 'center',hide:true},
                ]
            ],
            data: data? data : []
        });

        table.on('row(nytool)', function(obj){
            var data = obj.data;
            selMonth=data.code
            searchBtn()
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
            obj.tr.addClass('my_table_click').siblings().removeClass('my_table_click');

        })

    }

    function fpgrid(data) {

        var table = layui.table;
        //第2个实例
        table.render({
            elem: '#fapztable',
            height: "full-100",
            // width: 7* CLIENTWIDTH / 10,
            size: 'sm' ,
            page:false,
            limit:120000,
            cols:[        [
                {field: 'id',title: 'id',width: 300,sort: true,align: 'left',hide:true},
                {field: 'logid',title: 'logid',width: 300,sort: true,align: 'left',hide:true},
                {field: 'fileNameOrg',title: '文件名称',width: 300,sort: true,align: 'left'},
                {field: 'costdatatime',title: '数据年月',width: 200,sort: true,align: 'left'},
                {field: 'importTime',title: '上传时间',width: 200,sort: true,align: 'left' },
                {field: 'username',title: '上传用户账号',width: 200,sort: true,align: 'left' },
                {field: 'status', title: '状态', align: 'center', width: 200,  templet: function(d){
                        if(d.status==0){
                            return  '未同步'
                        }else if (d.status==1){
                            return  '已同步'
                        } else if (d.status==2){
                            return  '已废弃'
                        }
                        return ''

                    }},
                {field: 'operate', title: '操作', align: 'center', width: 300,  templet: function(d){
                        var str="";
                        if (d.status==1) {
                            str += '<button type="button" onclick="read(\''+d.id+'\')" class="layui-btn  layui-btn-xs layui_edit_btn">预览</button>';
                            str += '<button type="button" onclick="excelRead(\''+d.id+'\')" class="layui-btn  layui-btn-xs layui_edit_btn">Excel查看</button>';
                            str += '<button type="button" onclick="downFiled(\''+d.id+'\')" class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn">下载</button>';
                            str += '<button type="button" onclick="deleteData(\''+d.id+'\')" class="layui-btn layui-btn-danger layui-btn-xs layui_edit_btn">删除</button>';
                            str += '<button type="button" onclick="synchronous(\''+d.id+'\')" class="layui-btn layui-btn-warm layui-btn-xs layui_edit_btn">同步</button>';

                        }else {
                            str += '<button type="button" onclick="excelRead(\''+d.id+'\')" class="layui-btn  layui-btn-xs layui_edit_btn">Excel查看</button>';
                            str += '<button type="button" onclick="downFiled(\''+d.id+'\')" class="layui-btn layui-btn-normal layui-btn-xs layui_edit_btn">下载</button>';
                            str += '<button type="button" onclick="deleteData(\''+d.id+'\')" class="layui-btn layui-btn-danger layui-btn-xs layui_edit_btn">删除</button>';
                            str += '<button type="button" onclick="synchronous(\''+d.id+'\')" class="layui-btn layui-btn-warm layui-btn-xs layui_edit_btn">同步</button>';

                        }
                        return str;
                    }}

            ]] ,
            data: data? data : []
        });

        table.on('row(faptool)', function(obj){
            obj.tr.addClass('my_table_click').siblings().removeClass('my_table_click');
        })


    }

    function downFiled(logid) {
        window.open("/DevtExcelImportController/downFiled?id="+logid);
    }

    function downModel() {
        window.open("/DevtExcelImportController/downModel?excelId="+excelId);
    }
    function synchronous(id) {

        const postdata={id:id,
            year:$('#hsdate').val(),
            month:selMonth}
        dLong.post("/DevtExcelImportController/synchronous", postdata, function (obj) {
            if (obj.success) {
                dLong.layerMsg(obj.msg)
                searchBtn();
            } else {
                dLong.layerMsg(obj.msg)
                searchBtn();
            }
            layer.close(index);
        },true);
    }

    function deleteData(id) {

        const postdata={id:id}

        dlCommon.layerConfirm("是否确定删除该数据？",function(){
            dLong.post("/DevtExcelImportController/deleteData", postdata, function (res) {
                if (res.success) {
                    dlCommon.layerError(res.msg);
                    searchBtn();
                } else {
                    dlCommon.layerError(res.msg);
                    searchBtn();
                }
                layer.close(index);
            },true);
        })
    }

    function read(id) {



        dLong.layeropen(w*0.98,h*0.98,"预览","/DevtExcelImportController/read?id="+id+"&year="+$('#hsdate').val()+"&month="+selMonth)

    }

    function excelRead(id) {



        dLong.layeropen(w*0.98,h*0.98,"预览","/DevtExcelImportController/excelRead?id="+id+"&year="+$('#hsdate').val()+"&month="+selMonth)

    }

    function imortExcel() {

        if(!$('#hsdate').val()){
            dLong.layerSuccess("请选择数据年份！");
            return
        }
        if (!selMonth){
            dLong.layerMsg("请选择核算年月！")
            return;
        }

        dLong.layeropen(650,480,"Excel导入","/DevtExcelImportController/toEdit?excelId="+excelId+"&month="+selMonth+'&year='+$('#hsdate').val())

    }




</script>


</body>
</html>
